package com.liqy.api.domain;
/**
 * Created by
 *
 * @auth: liqy
 * on 2021/2/25 17:05.
 * desc:
 */

/**
 * @ClassName: CodeMsg
 * @Description: TODO
 * @Author: liqy
 * @CreateDate: 2021/2/25 17:05
 * @UpdateUser: liqy
 * @UpdateDate: 2021/2/25  17:05
 * @UpdateRemark: update TODO
 * @Version: 1.0
 */
public class CodeMsg {
    private int code;
    private String msg;

    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常:%s");

    public static CodeMsg REQUEST_WARN = new CodeMsg(400500, "参数校验异常：%s");
    public static CodeMsg BIND_ERROR = new CodeMsg(400501, "参数校验异常：%s");

    public int getCode() {
        return code;
    }


    public String getMsg() {
        return msg;
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }


    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
